package org.huel.backend.mapper;

import org.apache.ibatis.annotations.*;
import org.huel.backend.domain.entity.CourseCount;

@Mapper
public interface CourseCountMapper {

    /**
     * 查询最新的课程计数记录
     * @return 课程计数实体
     */
    @Select("SELECT * FROM course_count ORDER BY last_updated DESC LIMIT 1")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "totalCourses", column = "total_courses"),
            @Result(property = "lastUpdated", column = "last_updated")
    })
    CourseCount selectLatestCourseCount();

    /**
     * 插入新的课程计数记录
     * @param courseCount 课程计数实体
     * @return 影响的行数
     */
    @Insert("INSERT INTO course_count (total_courses) VALUES (#{totalCourses})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertCourseCount(CourseCount courseCount);

    /**
     * 更新课程计数记录
     * @param courseCount 课程计数实体
     * @return 影响的行数
     */
    @Update("UPDATE course_count SET total_courses = #{totalCourses} WHERE id = #{id}")
    int updateCourseCount(CourseCount courseCount);
}